package engine.display.Story 
{
	import com.greensock.TweenAlign;
	import com.greensock.TweenLite;
	
	import engine.data.ModelLocator;
	import engine.display.Story.ActionItem.BaseAction;
	import engine.display.Story.ActionItem.BlackTalkInfoUI;
	import engine.display.Story.ActionItem.FightXmlStory;
	import engine.display.Story.ActionItem.PlayStorySWF;
	import engine.display.Story.ActionItem.TalkInformationUI;
	import engine.display.Story.ActionItem.TalkMoveActionUI;
	import engine.display.Story.StoryMoveEvent.StoryEvent;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.events.EventDispatcher;
	import flash.utils.setTimeout;

	/**
	 * ...对话管理类
	 * @author WangHaiBo  www.woniu.com
	 */
	public class StoryActionManage extends EventDispatcher
	{
		/**黑幕*/
		private var blackInfoType:BlackTalkInfoUI;
		/**对话*/
		private var talkInfoType:TalkInformationUI;
		/**移动*/
		private var moveInfoType:TalkMoveActionUI
		
		private var swfInfoType:PlayStorySWF;
		
		private var fightInfoType:FightXmlStory;
		/**具体动作类型*/		
		private var talkItem:BaseAction;
		private static var _self:StoryActionManage;
		
		public function StoryActionManage()
		{
			blackInfoType	=	BlackTalkInfoUI.getInstance();
			talkInfoType	=	TalkInformationUI.getInstance();
			moveInfoType	=	TalkMoveActionUI.getInstance();
			swfInfoType		=	PlayStorySWF.getInstance();
			fightInfoType	=	FightXmlStory.getInstance();
		}
		public static function getInstance():StoryActionManage
		{
			if (_self == null) 
			{
				_self	=	new StoryActionManage();
			}
			return _self;
		}
		/**
		 * 显示内容
		 * @param	val 动作对象
		 * @param	disObj 显示容器
		 */
		public function showTalk(val:StoryVo, disObj:DisplayObjectContainer):void
		{
			StoryMoveUI.getInstance().changeSkipBtnState(false);
			if(val.type != 9)
			{
				while (disObj.numChildren > 0) 
				{
					disObj.removeChildAt(0);
				}
			}
			var talkType:int	=	val.type
			switch (talkType) 
			{
				case 1:
					talkItem	=	talkInfoType;
					if( ModelLocator.getInstance().scene.Role.GetProperties("VIPLevel") >=2 )
					{
						StoryMoveUI.getInstance().changeSkipBtnState(true);
					}
					break;
				case 2:
				case 9:
					talkItem	=	moveInfoType;
					break;
				case 3:
					talkItem	=	blackInfoType;
					break;
				case 10:
					talkItem	=	swfInfoType;
				case	11:
					talkItem	=	fightInfoType;
					break;
				default:
			}
			if (talkItem != null)
			{
				talkItem.showInfo(val);
				
//				if( talkItem == talkInfoType && talkInfoType.first )
//				{
//					talkInfoType.first = false;
//					talkInfoType.y += 200;
//					TweenLite.to( talkItem,.7, { y:"-200",
//						onComplete: function ():void
//						{
//							talkInfoType.againShowText();
//						}
//					});
//				}
			}
			disObj.addChild(talkItem);
			talkItem.addEventListener(StoryEvent.TALK_OVER, talkoverHandle);
		}
		/**
		 * 场景大小改变
		 * @param	stageWidth
		 */
		public function changeLocation(stageWidth:int,stageHeight:int):void
		{
			blackInfoType.changeLocation(stageWidth,stageHeight);
			talkInfoType.changeLocation(stageWidth,stageHeight);
		}
		/**
		 * 显示对话内容和表情
		 */		
		public function showTalkBoxInfo():void
		{
			
		}
		private function talkoverHandle(e:StoryEvent):void 
		{
			dispatchEvent(new StoryEvent(StoryEvent.TALK_OVER));
		}
	}

}